<?php 
## include required files
/*******************************/
require_once '../model/country.php';
require_once '../model/state.php';
require_once '../model/city.php';
/*******************************/
## Create Objects
/*******************************/
$countryObj = new Model_Country();
$stateObj=new Model_State();
$cityObj=new Model_City();
/*******************************/

if(isset($_POST['addcity_btn']) || $_POST['city_name']) {	
	## apply PHP validation for required filed
	if(trim($_POST['state_id']) != '') {
		
		if(trim($_POST['cityname']) != '' ) {
			
			extract($_POST);		
			$cityArray['country_id']    = 226;
			$cityArray['city_name']     = return_post_value($cityname);				
			$cityArray['state_id']      = return_post_value($state_id);
			$cityArray['city_status']   = 1;
			$cityObj->addCity($cityArray);
			$_SESSION['msg'] = "<div class='success_msg'><span>City added successfully!</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=city');
			exit;
		} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please enter city name</span></div>';
	}
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg">Please fill all required fields</span></div>';
	}
	// main if closed
}

## fetching all the country
$countryArray = $countryObj->getAllCountry();
$smarty->assign('countryArray', $countryArray);

##fetching all the state

	$stateArray = $stateObj->getAllStateWithActiveStatus();
	$smarty->assign('stateArray', $stateArray);


## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'city');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page
unset($countryObj);
unset($stateObj);
unset($cityObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'city/addcity.tpl');
unset($smarty);
?>